package com.mark.spring.annotation.auto.assembly.autowired;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @Description: 声明一个配置类，扫描指定包的bean，并在本配置类中还主动注入一个BookDao的bean
 * beanid为bookDao2
 * @Author: Mark
 * @CreateDate: 2019/5/26 21:51
 * @Version: 3.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Configuration
public class BookConfig {

    /**
     * 另外注入多一个BookDao的bean，并且@Primary说明当该bean存在多个的时候
     * 当在被在别的组件中注入的时候，默认使用该 Bean
     *
     * @return ：
     */
    @Primary
    @Bean(name = "bookDao2")
        public BookDao bookDao2() {
        BookDao bookDao = new BookDao();
        bookDao.setName("I am BookDao 2");
        return bookDao;
    }
}
